<?php
/**
 * 藏品列表模板
 * User: crstu
 * Date: 2016/5/3
 * Time: 11:06
 */

use kartik\grid\GridView;
use yii\helpers\Html;

$this->title = '商品列表';


$gridColumns = [
    ['class' => 'kartik\grid\SerialColumn'],

    [
        'label' => '产品名称',
        'attribute' => 'productID',
        'value' => 'product.title',
    ],
    [
        'label' => '产品图片',
        'attribute' => 'thumb',
        'value' => function($model){
            return Html::img($model->thumb, ['width' => 100 ,'height' => 100]);
        },
        'format' => 'raw',

    ],
    [
        'attribute' => 'isCover',
        'value' => function($model){
            if($model -> isCover){
                return "是";
            }else{
                return "否";
            }
        },
    ],
    [
        'format' => 'datetime',
        'attribute' => 'createTime',
        'filterType' => GridView::FILTER_DATE_RANGE,
        'filterWidgetOptions' => [
            'presetDropdown' => true,
            'pluginOptions' => [
                'locale' => [
                    'format' => 'YYYY/MM/DD',
                    'separator' => ' ~ ',
                    'language' => 'zh-CN',
                ]
            ],
            'pluginEvents' => [
                "apply.daterangepicker" => "function(){ aplicarDateRangeFilter('createTime') }",
            ],
        ],
    ],
    [
        'class' => 'common\widgets\KartikActionColumn',
        'items' => [
            ['删除', 'product-thumb/del', 'btn-danger'],
        ]
    ]
];

echo GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $model,
    'toolbar' => [
        ['content' => Html::a('<i class="glyphicon glyphicon-plus"></i> 添加产品图片', ['product-thumb/add','id'=>Yii::$app->request->get()['id']], ['class' => 'btn btn-primary'])],
        '{toggleData}'
    ],
    'panel' => [
        'type' => GridView::TYPE_DEFAULT,
        'heading' => $this->title,
    ],
    'columns' => $gridColumns,
]);